define(function() {
	return function($compile, $scope) {
		require(
				[ "AppPathDir/register/guideInfos/support",
						"AppPathDir/register/guideInfos/update",
						"AppPathDir/register/guideInfos/detail",
						"PDUtilDir/util", "PDUtilDir/inputSelect", "Date",
						"DateCN", "css!DateCss" ],
				function(Support, UpdateSupport, DetailSupport, Util, inputSelect) {
					/* 查询 start */
					$scope.cache = {
							statusMap: new Map(),
							status: new Array(),
							
							certificatesMap: new Map(),
							certificates: new Array()
					};
					$scope.search = {}
					$scope.searchSupport = {
						run : function() {
							$scope.grid.reload({
//								queryParam : {
//									model: JSON.stringify($scope.search)
//								}
								queryParam: $scope.search
							})
						}
					};
					/* 查询 end */
					$scope.updateSupport = UpdateSupport($scope, $compile);
					$scope.detailSupport = DetailSupport($scope, $compile);

//					$scope.delSupport = {
//						run : function() {
//							var selectRows = $scope.grid.getSelectedRow();
//							if (selectRows.length == 0) {
//								Util.alert('请选择至少一条的数据！');
//								return;
//							}
//							Util.confirm("是否要删除", function() {
//								var ids = new Array();
//								$.each(selectRows, function(index, selectRow) {
//									ids.push(selectRow.id);
//								});
//								$.ajax({
//									url : getServer()
//											+ "/flea/hclv/product/delete.htmls",
//									method : 'post',
//									data : {
//										'ids' : JSON
//												.stringify(ids)
//									},
//									success : function(
//                     if (data.status != 200) {
//                         return;
//                     }
//											data) {
//										$scope.grid
//												.refresh();
//										Util
//												.alert(data.message);
//									}
//								});
//							});
//						}
//					};
					$.ajax({
						url : getServer() + "/flea/hclv/getCertificates.htmls",
						success : function(data) {
							// console.info(data.status != 200);
                            if (data.status != 200) {
                                return;
                            }
							$scope.cache.certificates = data.data;
							$scope.init();
						}
					});
					$.ajax({
						url : getServer() + "/flea/hclv/getGuideAuditStatus.htmls",
						success : function(data) {
                            // console.info(data.status);
                            if (data.status != 200) {
                                return;
                            }
							$scope.cache.status = data.data;
							$.each(data.data, function(index, row) {
								$scope.cache.statusMap.set(row.dictCode, row.dictName);
							});
							$scope.init();
						}
					});
//					$.ajax({
//						url : getServer() + "/flea/hclv/getProvinces.htmls",
//						success : function(data) {
//                     if (data.status != 200) {
//                         return;
//                     }
//							$scope.cache.status = data.data;
//							// 初始化下拉框
//							inputSelect.dropCache();
//							inputSelect({
//								id : "queryAuditStatusName",
//								key : {
//									id : "dictCode",
//									name : "dictName",
//									data : "data",
//								},
//								data : $scope.cache.status,
//								simpleData : true,
//								// 启用文本搜索
//								// initData:[initProvice],
//								searchAble : false,
//								callback : function(id) {
//									$scope.search.queryAuditStatus = id[0];
//								}
//							});
//						}
//					});
					$.ajax({
						url : getServer() + "/flea/hclv/getProvinces.htmls",
						success : function(data) {
                            if (data.status != 200) {
                                return;
                            }
							$scope.cache.provinces = data.data;
							// 初始化下拉框
							inputSelect.dropCache();
							inputSelect({
								id : "queryProvinceName",
								key : {
									id : "dictCode",
									name : "dictName",
									data : "data",
								},
								data : $scope.cache.provinces,
								simpleData : true,
								// 启用文本搜索
								// initData:[initProvice],
								searchAble : false,
								callback : function(id) {
									$scope.search.queryProvince = id[0];
									$scope.getCity($scope.search.queryProvince);
								}
							});
						}
					});
					$scope.init = function() {
//						$scope.grid = Support.init($scope.cache, $scope.updateSupport, $scope.delSupport, $scope.detailSupport, $scope.searchSupport);
//                         console.info($scope.cache);
						if($scope.cache.status.length > 0 && $scope.cache.certificates.length > 0)
							$scope.grid = Support.init($scope.cache, $scope.updateSupport, $scope.detailSupport, $scope.searchSupport);
					};
					$scope.getCity = function(id) {
						$.ajax({
							url : getServer() + "/flea/hclv/getCity.htmls",
							data : {
								'pcode' : id
							},
							success : function(data) {
                                if (data.status != 200) {
                                    return;
                                }
								var citys = data.data;
								// 初始化下拉框
								inputSelect.dropCache();
								inputSelect({
									id : "queryCityName",
									key : {
										id : "dictCode",
										name : "dictName",
										data : "data",
									},
									data : citys,
									simpleData : true,
									// 启用文本搜索
									// initData:[initProvice],
									searchAble : false,
									callback : function(id) {
										$scope.search.queryCity = id[0];
									}
								});
							}
						});
					}
				})
	}
});